package enums;

import java.util.Random;

enum Outcome {
    WIN, DRAW, LOSE
}

enum Game {
    rock("石头", Outcome.DRAW, Outcome.WIN, Outcome.LOSE),
    scissors("剪刀", Outcome.LOSE, Outcome.DRAW, Outcome.WIN),
    paper("布", Outcome.WIN, Outcome.LOSE, Outcome.DRAW);

    private Outcome or, os, op;
    private String name;
    Game(String name, Outcome or, Outcome os, Outcome op) {
        this.name = name;
        this.or = or;
        this.os = os;
        this.op = op;
    }
    public Outcome compete(Game other) {
        switch(other) {
            case rock:
                return this.or;
            case scissors:
                return this.os;
            case paper:
                return this.op;
        }
        return Outcome.DRAW;
    }

    @Override
    public String toString() {
        return this.name;
    }
}

/**
 * 石头剪刀布
 */
public class RoShamBo {

    private static Game[] games = Game.values();
    private static Random random = new Random();

    static Game newGame() {
        return games[random.nextInt(games.length)];
    }

    static void play(Game g1, Game g2) {
        System.out.printf("%-2s vs %-2s  =>  %s\n", g1, g2, g1.compete(g2));
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++)
            play(newGame(), newGame());
    }
}
